package com.thekernel.youdaoyun.exception;

import com.thekernel.youdaoyun.util.ResponseUtils;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.mail.MessagingException;

/**
 * @Author TheKernel
 * @Date 2019/9/29 5:22 下午
 * @Version 1.0
 * @Description 异常处理类
 */
@ControllerAdvice
public class ControllerExceptionHandler {

    @ExceptionHandler(MyException.class)
    @ResponseBody
    @ResponseStatus(value = HttpStatus.OK)
    public String handleMyException(MyException ex) {
        return ex.getMessage();
    }

    @ExceptionHandler(MessagingException.class)
    @ResponseBody
    @ResponseStatus(value = HttpStatus.OK)
    public String handleMessagingException(MessagingException ex) {
        return ResponseUtils.response(404, ex.getMessage(), null);
    }

}
